<?php
/**
 * Created by PhpStorm.
 * User: liuxiaojie
 * Date: 2019-03-28
 * Time: 22:37
 */

namespace app\tools;

class Express
{

    public $key = "27292cdf6f2419f068c37923a06be2a9";

    function search($no, $type){

        $url = "http://v.juhe.cn/exp/index?key=".$this->key."&com=".$type."&no=".$no;

        $data = curl($url);

//        file_put_contents('1.txt', $data);

        $data = json_decode($data, true);

        if($data['error_code'] != 0){
            exit(fail("EXPRESS_NOT_FOUND"));
        }

        $result = $data['result'];

        return [
            "express"=> $result['company'],
            "type"=> $result['com'],
            "express_no"=> $result['no'],
            "detail"=> $result['list'],
            "status"=> $result['status']
        ];

    }

}